﻿using MediatR;
using SystemHYS.API.Application.command.DeliveryCommand;
using SystemHYS.Domian;
using SystemHYS.Infrstructre.Interface;
namespace SystemHYS.API.Application.commandler.DeliveryCommandler
{
    public class DeliveryShowCommandler : IRequestHandler<DeliveryShowCommand, List<Delivery>>
    {
        IDeliveryRepository deliveryRepository;
        public DeliveryShowCommandler(IDeliveryRepository deliveryRepository)
        {
            this.deliveryRepository = deliveryRepository;
        }
        public async Task<List<Delivery>> Handle(DeliveryShowCommand request, CancellationToken cancellationToken)
        {
            var list =(from a in await deliveryRepository.GetAllAsnc() where a.isDel == false select a).ToList();
            if (request.state != null)
            {
                list = list.Where(x => x.state == request.state).ToList();
            }
            if (request.finishedProductNumber != null)
            {
                list = list.Where(x => x.finishedProductNumber == request.finishedProductNumber).ToList();
            }
            if (request.deliveryNumber != null)
            {
                list = list.Where(x => x.deliveryNumber == request.deliveryNumber).ToList();
            }
            return list;
        }
    }
}
